﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface; 

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTFactoryCertificateService : ServiceHandle, IRPTFactoryCertificate
    {
        #region IRPTFactoryCertificate Members

        public OperationResult<List<tb_RPT_FactoryCertificate>> GetAllFactoryCertificate()
        {
            OperationResult<List<tb_RPT_FactoryCertificate>> result = new OperationResult<List<tb_RPT_FactoryCertificate>>();
            List<tb_RPT_FactoryCertificate> list = new List<tb_RPT_FactoryCertificate>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllFactoryCertificate();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_FactoryCertificate>> GetFactoryCertificateBySequence(string strSequence)
        {
             OperationResult<List<tb_RPT_FactoryCertificate>> result = new OperationResult<List<tb_RPT_FactoryCertificate>>();
            List<tb_RPT_FactoryCertificate> list = new List<tb_RPT_FactoryCertificate>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetFactoryCertificateBySequence(strSequence);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_FactoryCertificate>> GetFactoryCertificateByProjectName(string strProjectName)
        {
            OperationResult<List<tb_RPT_FactoryCertificate>> result = new OperationResult<List<tb_RPT_FactoryCertificate>>();
            List<tb_RPT_FactoryCertificate> list = new List<tb_RPT_FactoryCertificate>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetFactoryCertificateByProjectName(strProjectName);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_FactoryCertificate>> GetFactoryCertificateByContition(string strProjectName, string strSequence, string strBuyer, string strSupplier)
        {
            OperationResult<List<tb_RPT_FactoryCertificate>> result = new OperationResult<List<tb_RPT_FactoryCertificate>>();
            List<tb_RPT_FactoryCertificate> list = new List<tb_RPT_FactoryCertificate>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetFactoryCertificateByContition(  strProjectName,   strSequence,   strBuyer,   strSupplier);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_FactoryCertificate> GetFactoryCertificateById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_FactoryCertificate> result = new OperationResult<tb_RPT_FactoryCertificate>();
            tb_RPT_FactoryCertificate factoryCertificate;
            try
            {
                factoryCertificate = dataContext.GetFactoryCertificateById(id);
                if (factoryCertificate == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = factoryCertificate;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_FactoryCertificate> CreateFactoryCertificate(tb_RPT_FactoryCertificate entity)
        {
            OperationResult<tb_RPT_FactoryCertificate> result = new OperationResult<tb_RPT_FactoryCertificate>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateFactoryCertificate(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_FactoryCertificate> ModifyFactoryCertificate(tb_RPT_FactoryCertificate entity)
        {
            OperationResult<tb_RPT_FactoryCertificate> result = new OperationResult<tb_RPT_FactoryCertificate>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifyFactoryCertificate(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_FactoryCertificate> DeleteFactoryCertificate(tb_RPT_FactoryCertificate entity)
        {
            OperationResult<tb_RPT_FactoryCertificate> result = new OperationResult<tb_RPT_FactoryCertificate>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteFactoryCertificate(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
